package iva;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class Proveedor {

	private long codigo;
	private String apenom;
	private Object condiva;
	private String cuit;
	private Object codprov;

	public long getCodigo() {
		return codigo;
	}
	public void setCodigo(long codigo) {
		this.codigo = codigo;
	}
	public String getApenom() {
		return apenom;
	}
	public void setApenom(String apenom) {
		this.apenom = apenom;
	}
	public Object getCondiva() {
		return condiva;
	}
	public void setCondiva(Object object) {
		this.condiva = object;
	}
	public String getCuit() {
		return cuit;
	}
	public void setCuit(String cuit) {
		this.cuit = cuit;
	}
	public Object getCodprov() {
		return codprov;
	}
	public void setCodprov(Object object) {
		this.codprov = object;
	}
	
	public Proveedor(long codigo) {
		super();
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/addisyc","", "");
			String query="SELECT DISTINCT CODIGO, NOMBRE, CONDIVA, CUIT, CODPROVI FROM proveedo WHERE CODIGO = ?";
			PreparedStatement ps = con.prepareStatement(query);
			ps.setLong(1, codigo);
			ps.execute();
			ResultSet rs = ps.getResultSet();

			while (rs.next()){
				this.codigo = codigo;
				this.apenom = rs.getString(2);
				this.condiva = rs.getObject(3);
				this.cuit = rs.getString(4);
				this.codprov = rs.getObject(5);
			}	

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public Proveedor() {
		// TODO Auto-generated constructor stub
	}
	public String getProveedorName(Object codigo){
		String nombre = "";
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/addisyc","", "");
			String query="SELECT DISTINCT NOMBRE FROM proveedo WHERE CODIGO = ?";
			PreparedStatement ps = con.prepareStatement(query);
			ps.setObject(1, codigo);
			ps.execute();
			
			ResultSet rs = ps.getResultSet();
			rs.next();
			nombre = rs.getString(1);

		} catch (Exception e) {
			e.printStackTrace();
		}
		return nombre;

	}
	
	
	
	public static void main(String[] args) {
		long codigo = Long.parseLong(args[0]);
		Proveedor prov = new Proveedor(codigo);
		System.out.println(prov.getCodigo());
		System.out.println(prov.getApenom());
		System.out.println(prov.getCondiva());
		System.out.println(prov.getCuit());
		System.out.println(prov.getCodprov());

	
	
	}
	
	
	
	
	
	
	
	
	
}
